// pages/groupDetails/groupDetails.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    fullHeight: app.globalData.fullcontain,
    navmess: {
      navtitle: "拼团详情",
      backhide: 0,
      topheight: 1,
    },
    toshareobj: {
      "lacknum": 2,
    },
    shareflag: false,
    currentTab: 0,
    height: 0,   //单个main高度
    widHeight: 0,  //swiper高度
    //拼团中
    groupinglist: [
      {
        "lackNum": "2",
        "goodsPrice": 128,
        "vipprice": 99,
        "spellGroupPrice": 67,
        "name": "拼团按摩",
        "imageUrl": "./images/groupimg.png",
        "limitPeople": 4,
        "store": "全部",
        "activityNo": "MX0901",
        "spellGroupNo": "963258",
        "spellGroupOrderId": 3,
        "sign": "日本 Dance丹盛激光美白仪，深度美白，去皱，紧致脸部",
        "lackPeoples": 1
      },
      {
        "lackNum": "1",
        "goodsPrice": 128,
        "vipprice": 99,
        "spellGroupPrice": 67,
        "name": "拼团",
        "imageUrl": "./images/groupimg.png",
        "limitPeople": 4,
        "store": "全部",
        "activityNo": "MX0901",
        "spellGroupNo": "963258",
        "spellGroupOrderId": 3,
        "sign": "日本 Dance丹盛激光美白仪，深度美白，去皱，紧致脸部",
        "lackPeoples": 1
      }
    ],
    //拼团成功
    groupsuccess: [
      {
        "goodsPrice": 128,
        "vipprice": 99,
        "spellGroupPrice": 67,
        "name": "拼团按摩",
        "imageUrl": "./images/groupimg.png",
        "limitPeople": 4,
        "store": "全部",
        "activityNo": "MX0901",
        "spellGroupNo": "963258",
        "spellGroupOrderId": 3,
        "sign": "日本 Dance丹盛激光美白仪，深度美白，去皱，紧致脸部",
        "lackPeoples": 1
      },
    ],
    //拼团失败
    groupfail: [
      {
        "goodsPrice": 128,
        "vipprice": 99,
        "spellGroupPrice": 67,
        "name": "拼团按摩",
        "imageUrl": "./images/groupimg.png",
        "limitPeople": 4,
        "store": "全部",
        "activityNo": "MX0901",
        "spellGroupNo": "963258",
        "spellGroupOrderId": 3,
        "sign": "日本 Dance丹盛激光美白仪，深度美白，去皱，紧致脸部",
        "lackPeoples": 1
      },
      {
        "goodsPrice": 128,
        "vipprice": 99,
        "spellGroupPrice": 67,
        "name": "拼团按摩",
        "imageUrl": "./images/groupimg.png",
        "limitPeople": 4,
        "store": "全部",
        "activityNo": "MX0901",
        "spellGroupNo": "963258",
        "spellGroupOrderId": 3,
        "sign": "日本 Dance丹盛激光美白仪，深度美白，去皱，紧致脸部",
        "lackPeoples": 1
      }
    ],
  },
  // 动态获取赋值swiper-item高度
  savecurheight: function(count){
    var that = this,
        curmain =  '.main' + count,
        query = wx.createSelectorQuery().in(this);

    query.select(curmain).boundingClientRect(function (rect) { 
      console.log(rect)
      that.setData({
        height: rect.height
      })

      // 获取单个轮播循环的高度
      var heights=that.data.height;
      console.log(heights)
      // 获取一级成员的数组个数
      var item0 = that.data.groupinglist.length;
      // 获取二级成员的数组个数
      var item1 = that.data.groupsuccess.length;
      // 获取三级成员的数组个数
      var item2 = that.data.groupfail.length;
      
      if (that.data.currentTab==0){
        that.setData({
          widHeight: heights * item0+"px"
        });

      }else if(that.data.currentTab==1){
        that.setData({
          widHeight: heights * item1 + "px"
        });
        
      }else if(that.data.currentTab==2){
        that.setData({
          widHeight: heights * item2 + "px"
        });
        
      }
    }).exec();
    // 顶部开始显示
    this.setData({
      topNum: 0
    })
  },
  // 滑动切换tab
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
    this.savecurheight(e.detail.current);
  },
  // 点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  pageto: function(e){
    var url = e.currentTarget.dataset.url,
        data = e.currentTarget.dataset.datobj;
    app.goto(url,data);
  },
  toshare: function(e){
    var that = this;
    that.setData({
      shareflag: true
    })
  },
  closebackfn: function(e){
    var that = this;
    console.log("shareback",e.detail); //子组件返回参数
    that.setData({
      shareflag: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.savecurheight(0);  //默认取索引为0swiper高度
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})